<template>
  <Dialogdrawerdefect
    title="批量加减限制条件"
    :ddtvisible.sync="dialogVisible"
    :show-close="true"
    :modal="true"
    size="800px"
    @close="close">
    <div style="padding: 0px 20px;">
      <ruleTemplate ref="ruleTemplate" :hospital-code="hospitalCode" :dep="dep"></ruleTemplate>
      <div class="nsc-footer flex flex-row justify-between">
        <el-button size="small" @click="dialogVisible = false">取消</el-button>
        <div>
          <el-radio-group v-model="batchType" @input="batchTypeChange">
            <el-radio label="add">批量加</el-radio>
            <el-radio label="sub">批量减</el-radio>
          </el-radio-group>
          <el-button class="mar-l-30" size="small" type="primary" @click="sureSubmit">确定</el-button>
        </div>
      </div>
    </div>
  </Dialogdrawerdefect>
</template>

<script>
import { Options } from '@/utils/constant'
import Dialogdrawerdefect from '@/components/dialogbox/dialogDrawerDefect'
import ruleTemplate from './ruleTemplate'
export default {
  props: {
    dep: String,
    hospitalCode: String,
    isOpenDialog: Boolean,
    appoStatus: String
  },
  components: {
    Dialogdrawerdefect,
    ruleTemplate
  },
  data() {
    return {
      batchType: 'add',
      formdata: {
        id: 0,
        beginTime: '',
        endTime: '',
        addNum: '', // 追加
        reserveNum: '', // 预留号码
        recordCode: '', // 模板标题，
        templateName: '', // 添加到参数模板的模板标题
        initialNum: '', // 初始号码
        startNum: '', // 初始号码
        checkNum: '', // 检查数量
        status: '', // 状态
        appointmentStatus: '',
        color: '', // 颜色
        appointmentFilters: [
          // {
          //   parametersType: '',
          //   parametersValues: '',
          //   parametersName: ''
          // }
        ], // 过来规则
        channel: [],
        check: []
      },
      appointmentStatusOptions: Options.appointmentStatusOptions
    }
  },
  computed: {
    dialogVisible: {
      get() {
        return this.isOpenDialog
      },
      set(val) {
        this.$emit('update:isOpenDialog', val)
      }
    }
  },
  watch: {
    isOpenDialog(val) {
      if (val) {
        this.$nextTick(() => {
          console.log('dep=>', this.dep)
          this.$refs.ruleTemplate && this.$refs.ruleTemplate.init(this.formdata)
        })
      }
    }
  },
  methods: {
    // 退出
    close() {
      console.log('close')
      this.dialogVisible = false
      this.$store.dispatch('app/toggleTempVisible', false)
      this.$emit('closeTempDlg')
    },
    batchTypeChange(value) {
      console.log('batchTypeChang=>value', value)
    },
    async sureSubmit() {
      const ruleParams = await this.$refs.ruleTemplate.getRuleData()
      console.warn('ruleParams111', ruleParams)
      let ruleParamsNew = JSON.parse(ruleParams)
      ruleParamsNew.batchType = this.batchType
      console.warn('ruleParams222', ruleParamsNew)
      console.log('=========================')
      if (!ruleParamsNew.appointmentFilters.length) {
        this.$confirm(`请选择至少一个限制条件！`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          showCancelButton: false,
          type: 'warning'
        }).then((e) => {
          // // console.log('e', e)
          if (e == 'confirm') {
            console.log('e', e)
          } else {
            // // console.log('cancel')
          }
        }).catch(() => {})
      } else {
        this.$confirm(`您当前选择的是【批量${ruleParamsNew.batchType == 'add' ? '加' : '减'}】, 请问是否继续?`, '提示', {
          confirmButtonText: '继续',
          cancelButtonText: '取消',
          type: 'warning'
        }).then((e) => {
          // // console.log('e', e)
          if (e == 'confirm') {
            console.log('e', e)
            this.$emit('handleBatchAddSubAppoFilters', ruleParamsNew)
          } else {
            // // console.log('cancel')
          }
        }).catch(() => {})
      }
    }
  }
}
</script>

<style lang="scss" scoped>
/deep/ .el-drawer__header{
  margin-bottom: 0px !important;
  font-size: 16px;
  font-weight: bold;
  color: #333333;
}
.nsc-footer{
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: 2;
    width: 100%;
    text-align: right;
    padding: 10px 20px;
    border-top: solid 1px #DCDFE6;
    background-color: #fff;
  }
</style>
